<?php
 /**
   * Admin Index Controller
   */
  NAMESPACE Admin\Controller;
  USE Think\Controller;
  class IndexController extends Controller{
  	/*后台登录*/
 	public function login(){
 		if(IS_POST){
 			$checkcode=I('post.checkcode');
 			$Verify=new \Think\Verify();
 			if($Verify->check($checkcode)){
 				$name=I('post.name');
 				$password=md5(I('post.password'));
 				$adminUser=D('AdminUser');
 				if($adminUser->create()){
 					$adminInfo=$adminUser->where("name='$name' and password='$password'")->find();
 					if($adminInfo){
 						$id=$adminInfo['id'];
	 					session('adminInfo',$adminInfo);//保存管理员信息
	 					$data['login_time']=time();
	 					$data['login_ip']=$_SERVER['REMOTE_ADDR'];
	 					$adminUser->where("id=$id")->save($data);
	 					$this->success('登录成功！','index');	
 					}else{
 						$this->error('用户名或密码错误','login');
 					} 					
 				}else{
 					$this->error($adminUser->getError());
 				}
 			}else{
 				$this->error('请输入验证码','login');
 			}
 		}else{
 			$this->display();
 		} 		
 	}
 	public function index(){
    if(session('?adminInfo')){
      $this->assign('adminInfo',session('adminInfo'));
      $this->assign('currentTime',date('H',time()));
      $this->display();
    }else{
      $this->error('请先登录','login',3);
    }
 	}
  /*系统配置*/
  public function setting(){
    $this->display();
  }
 	/*验证码*/
 	public function code(){
 		$Verify=new \Think\Verify();
 		$Verify->fontSize=13;
 		$Verify->length=4;
 		$Verify->useCurve=false;
 		$Verify->useNoise=false;
 		$Verify->inageW=100;
 		$Verify->inageH=30;
 		$Verify->bg=array(255, 255, 255);
 		$Verify->entry();
 	}
  }
       